package com.example.loginpilot_01.pojo.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 通知统计数据传输对象
 * 用于封装通知的阅读统计信息
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class NoticeStatDTO {
    // 通知ID
    private Long announcementId;

    // 总阅读人数
    private Long totalReadCount;

    // 今日阅读人数
    private Long todayReadCount;

    // 阅读率（百分比，0-100）
    private Double readRate;

    // 构造函数 - 包含通知ID、总阅读人数和今日阅读人数
    public NoticeStatDTO(Long announcementId, Long totalReadCount, Long todayReadCount) {
        this.announcementId = announcementId;
        this.totalReadCount = totalReadCount;
        this.todayReadCount = todayReadCount;
    }

    // 计算并设置阅读率
    public void calculateReadRate(Long totalUsers) {
        if (totalUsers != null && totalUsers > 0) {
            this.readRate = (double) totalReadCount / totalUsers * 100;
            // 保留两位小数
            this.readRate = Math.round(this.readRate * 100.0) / 100.0;
        }
    }

    // 获取格式化后的阅读率（带百分号）
    public String getFormattedReadRate() {
        if (readRate == null) {
            return "0%";
        }
        return String.format("%.2f%%", readRate);
    }
}